package cn.stylefeng.guns.modular.gridsystem.netty.ws;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.util.concurrent.GlobalEventExecutor;

/**
 * @author ssy
 * @date 2022/3/26 13:34
 */
public class MyChannelHandlerPool {

    public MyChannelHandlerPool(){}

    static ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);

    public static void sendAllMessage(String message){
        //群发给所有channel
        MyChannelHandlerPool.channelGroup.writeAndFlush( new TextWebSocketFrame(message));
    }

    public static void sendMessage(ChannelHandlerContext ctx,String message){
        //单独发送
        ctx.writeAndFlush( new TextWebSocketFrame(message));
    }

}
